// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AssertionExtensions.cs" company="CSLib.Net Team">
//   Copyright (c) Roman "4ux-nbIx" Novitsky 2010
// </copyright>
// <summary>
//   Defines the AssertExtensions type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

#define DEBUG

namespace CSLib.Net.Extensions
{
  #region Namespace Imports

  using System;
  using System.Diagnostics;

  using Annotations;

  using Diagnostics;

  #endregion

  // ReSharper disable ValueAnalysis

  /// <summary>
  /// Defines various assertion extension methods.
  /// </summary>
  [DebuggerStepThrough]
  [DebuggerNonUserCode]
  [UsedImplicitly(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.WithMembers)]
  public static class AssertionExtensions
  {
    #region Public Methods

    /// <summary>
    /// Generates assert if specified method argument is <c>null</c>.
    /// </summary>
    /// <param name="argument">
    /// An argument value to check.
    /// </param>
    /// <param name="argumentName">
    /// A name of an argument.
    /// </param>
    [Conditional("DEBUG")]
    [AssertionMethod]
    public static void AssertArgumentNotNull(
      [AssertionCondition(AssertionConditionType.IS_NOT_NULL)] this object argument, 
      [InvokerParameterName] [NotNull] string argumentName)
    {
      Assert.ArgumentNotNull(argument, argumentName);
    }


    /// <summary>
    /// Asserts that the specified argument value is not <c>null</c> or white space.
    /// </summary>
    /// <param name="value">
    /// The value to check.
    /// </param>
    /// <param name="argumentName">
    /// Name of the argument.
    /// </param>
    [Conditional("DEBUG")]
    [AssertionMethod]
    public static void AssertArgumentNotNullOrEmpty(
      [AssertionCondition(AssertionConditionType.IS_NOT_NULL)] this string value, 
      [InvokerParameterName] [NotNull] string argumentName)
    {
      Assert.ArgumentNotNullOrEmpty(value, argumentName);
    }


    /// <summary>
    /// Asserts that the specified argument value is not <c>null</c> or white space.
    /// </summary>
    /// <param name="value">
    /// The value to check.
    /// </param>
    /// <param name="argumentName">
    /// Name of the argument.
    /// </param>
    [Conditional("DEBUG")]
    [AssertionMethod]
    public static void AssertArgumentNotNullOrWhiteSpace(
      [AssertionCondition(AssertionConditionType.IS_NOT_NULL)] this string value, 
      [InvokerParameterName] [NotNull] string argumentName)
    {
      Assert.ArgumentNotNullOrWhiteSpace(value, argumentName);
    }


    /// <summary>
    /// Asserts whether the specified condition is <c>false</c>.
    /// </summary>
    /// <param name="condition">
    /// The evaluation condition.
    /// </param>
    /// <param name="messageFormat">
    /// A <see cref="System.String"/> containing a message format.
    /// </param>
    /// <param name="messageArguments">
    /// An array of message arguments to format.
    /// </param>
    [Conditional("DEBUG")]
    [AssertionMethod]
    [StringFormatMethod("messageFormat")]
    public static void AssertIsFalse(
      [AssertionCondition(AssertionConditionType.IS_FALSE)] this bool condition, 
      [NotNull] string messageFormat, 
      [CanBeNull] params object[] messageArguments)
    {
      Assert.IsFalse(condition, messageFormat, messageArguments);
    }


    /// <summary>
    /// Asserts whether specified object is not <c>null</c>.
    /// </summary>
    /// <param name="value">
    /// An <see cref="System.Object"/> to check.
    /// </param>
    /// <param name="messageFormat">
    /// A composite format <see cref="string"/>.
    /// </param>
    /// <param name="messageArguments">
    /// An array of message arguments to format.
    /// </param>
    [Conditional("DEBUG")]
    [AssertionMethod]
    [StringFormatMethod("messageFormat")]
    public static void AssertIsNotNull(
      [AssertionCondition(AssertionConditionType.IS_NOT_NULL)] this object value, 
      [NotNull] string messageFormat, 
      [CanBeNull] params object[] messageArguments)
    {
      Assert.IsNotNull(value, messageFormat, messageArguments);
    }


    /// <summary>
    /// Asserts that the specified string is not <c>null</c> or empty.
    /// </summary>
    /// <param name="value">
    /// A <see cref="System.String"/> value to check.
    /// </param>
    /// <param name="messageFormat">
    /// A message format to display.
    /// </param>
    /// <param name="messageArguments">
    /// An array of message arguments to format.
    /// </param>
    [Conditional("DEBUG")]
    [AssertionMethod]
    [StringFormatMethod("messageFormat")]
    public static void AssertIsNotNullOrEmpty(
      [AssertionCondition(AssertionConditionType.IS_NOT_NULL)] this string value, 
      [NotNull] string messageFormat, 
      [CanBeNull] params object[] messageArguments)
    {
      Assert.IsNotNullOrEmpty(value, messageFormat, messageArguments);
    }


    /// <summary>
    /// Asserts that the specified string is not <c>null</c> or white space.
    /// </summary>
    /// <param name="value">
    /// A <see cref="System.String"/> value to check.
    /// </param>
    /// <param name="messageFormat">
    /// A message to display.
    /// </param>
    /// <param name="messageArguments">
    /// An array of message arguments to format.
    /// </param>
    [Conditional("DEBUG")]
    [AssertionMethod]
    [StringFormatMethod("messageFormat")]
    public static void AssertIsNotNullOrWhiteSpace(
      [AssertionCondition(AssertionConditionType.IS_NOT_NULL)] this string value, 
      [NotNull] string messageFormat, 
      [CanBeNull] params object[] messageArguments)
    {
      Assert.IsNotNullOrWhiteSpace(value, messageFormat, messageArguments);
    }


    /// <summary>
    /// Asserts whether specified object is <c>null</c>.
    /// </summary>
    /// <param name="value">
    /// An <see cref="System.Object"/> to check.
    /// </param>
    /// <param name="messageFormat">
    /// A composite format <see cref="string"/>.
    /// </param>
    /// <param name="messageArguments">
    /// An array of message arguments to format.
    /// </param>
    [Conditional("DEBUG")]
    [AssertionMethod]
    [StringFormatMethod("messageFormat")]
    public static void AssertIsNull(
      [AssertionCondition(AssertionConditionType.IS_NULL)] [CanBeNull] this object value, 
      [NotNull] string messageFormat, 
      [CanBeNull] params object[] messageArguments)
    {
      Assert.IsNull(value, messageFormat, messageArguments);
    }


    /// <summary>
    /// Asserts that the specified string is <c>null</c> or empty.
    /// </summary>
    /// <param name="value">
    /// A <see cref="System.String"/> value to check.
    /// </param>
    /// <param name="messageFormat">
    /// A message to display.
    /// </param>
    /// <param name="messageArguments">
    /// An array of message arguments to format.
    /// </param>
    [Conditional("DEBUG")]
    [AssertionMethod]
    [StringFormatMethod("messageFormat")]
    public static void AssertIsNullOrEmpty(
      [CanBeNull] this string value, [NotNull] string messageFormat, [CanBeNull] params object[] messageArguments)
    {
      Assert.IsNullOrEmpty(value, messageFormat, messageArguments);
    }


    /// <summary>
    /// Asserts that the specified string is <c>null</c> or white space.
    /// </summary>
    /// <param name="value">
    /// A <see cref="System.String"/> value to check.
    /// </param>
    /// <param name="messageFormat">
    /// A message to display.
    /// </param>
    /// <param name="messageArguments">
    /// An array of message arguments to format.
    /// </param>
    [Conditional("DEBUG")]
    [AssertionMethod]
    [StringFormatMethod("messageFormat")]
    public static void AssertIsNullOrWhiteSpace(
      [CanBeNull] this string value, [NotNull] string messageFormat, [CanBeNull] params object[] messageArguments)
    {
      Assert.IsNullOrWhiteSpace(value, messageFormat, messageArguments);
    }


    /// <summary>
    /// Asserts that the specified object is of specified type.
    /// </summary>
    /// <param name="instance">
    /// An instance of a <see cref="System.Object"/>.
    /// </param>
    /// <param name="type">
    /// An instance of a <see cref="System.Type"/>.
    /// </param>
    /// <param name="messageFormat">
    /// A <see cref="System.String"/> containing composite message format.
    /// </param>
    /// <param name="messageArguments">
    /// An array of message arguments to format.
    /// </param>
    [Conditional("DEBUG")]
    [StringFormatMethod("messageFormat")]
    public static void AssertIsOfType(
      this object instance, 
      [NotNull] Type type, 
      [NotNull] string messageFormat, 
      [CanBeNull] params object[] messageArguments)
    {
      Assert.IsOfType(instance, type, messageFormat, messageArguments);
    }


    /// <summary>
    /// Asserts whether the specified condition is <c>true</c>.
    /// </summary>
    /// <param name="condition">
    /// The evaluation condition.
    /// </param>
    /// <param name="messageFormat">
    /// A <see cref="System.String"/> containing a message format.
    /// </param>
    /// <param name="messageArguments">
    /// An array of message arguments to format.
    /// </param>
    [Conditional("DEBUG")]
    [AssertionMethod]
    [StringFormatMethod("messageFormat")]
    public static void AssertIsTrue(
      [AssertionCondition(AssertionConditionType.IS_TRUE)] this bool condition, 
      [NotNull] string messageFormat, 
      [CanBeNull] params object[] messageArguments)
    {
      Assert.IsTrue(condition, messageFormat, messageArguments);
    }


    #endregion
  }
}